/**
 * @param {number} m
 * @param {number} n
 * @param {number} cnt
 * @return {number}
 */
var wardrobeFinishing = function(m, n, cnt) {
    const visited = Array.from({ length: m }, () => Array(n).fill(false));
    function digit(x){
        let sum=0
        while(x>0){
            count+=x%10
            Math.floor(x / 10);
        }
        return sum
    }
    function dfs(i, j) {
        if (i < 0 || i >= m || j < 0 || j >= n || visited[i][j] || digit(i) + digit(j) > cnt) {
            return 0;
        }
        visited[i][j] = true;
        return 1 + dfs(i + 1, j) + dfs(i, j + 1);
    }
    function bfs(){
        const queue = [[0, 0]];
        let count = 0;
        while (queue.length > 0) {
            const [i, j] = queue.shift();
            if (i < 0 || i >= m || j < 0 || j >= n || visited[i][j] || digit(i) + digit(j) > cnt) {
                continue;
            }
            visited[i][j] = true;
            count++;
            queue.push([i + 1, j]);
            queue.push([i, j + 1]);
        }
        return count;
    }

    return dfs(0, 0);
};